package za.ac.sun.cs.distrib.logging;

import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class LogFormatter extends Formatter {

	private static String id = "";

	private static final String noTimeFormat = "@@ %s @@ %s%n";

	private static final String timeFormat = "@@ %d @@ %s @@ %s%n";
	
	private final boolean prependTime;
	
	public LogFormatter(boolean prependTime) {
		super();
		this.prependTime = prependTime;
	}

	public static void setId(String id) {
		LogFormatter.id = id;
	}

	@Override
	public synchronized String format(LogRecord record) {
		if (prependTime) {
			return String.format(timeFormat, record.getMillis(), id, formatMessage(record));
		} else {
			return String.format(noTimeFormat, id, formatMessage(record));
		}
	}

}
